package com.company.common.server.config.cloud;

import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class LocalDateTimeSerializerConfig {
	
//	@org.springframework.beans.factory.annotation.Value("${spring.jackson.date-format:yyyy-MM-dd HH:mm:ss}")
//	private String pattern;
//	
//	@Bean
//	public LocalDateTimeSerializer localDateTimeDeserializer() {
//		return new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(pattern));
//	}
//	@Bean
//	public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
//		return builder -> builder.serializerByType(LocalDateTime.class, localDateTimeDeserializer());
//	}
	
	@Bean
	public HttpMessageConverters fastJsonConfigure() {
      FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
      FastJsonConfig fastJsonConfig = new FastJsonConfig();
      fastJsonConfig.setSerializerFeatures(
    			SerializerFeature.DisableCircularReferenceDetect,
    			SerializerFeature.WriteNullStringAsEmpty,
    			SerializerFeature.WriteNullListAsEmpty,
    			SerializerFeature.WriteNullBooleanAsFalse,
    			SerializerFeature.SortField
    		  );
      fastJsonConfig.setFeatures(Feature.OrderedField);
      //附加：处理中文乱码（后期添加）
      List<MediaType> fastMedisTypes=new ArrayList<MediaType>();
      fastMedisTypes.add(MediaType.APPLICATION_JSON_UTF8);
      converter.setSupportedMediaTypes(fastMedisTypes);

      //日期格式化
      fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
      converter.setFastJsonConfig(fastJsonConfig);
      return new HttpMessageConverters(converter);
	}
	
	


	
	
	
}
